package com.masterclient.app.businessmodule.settingmodule.index.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.common.bean.base.CommonBaseBean;
import com.masterclient.app.businessmodule.settingmodule.api.SettingHttpService;
import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
* Created by TMVPHelper on 2017/07/19
*/
public class SettingPresenter extends SettingContract.Presenter{

    @Override
    public void logout(String customerid) {
        long timestamp = System.currentTimeMillis()/1000;
        Observable<CommonBaseBean> observable = SettingHttpService.getInstance().logout();
        Disposable disposable = toSubscribe(observable, new Consumer<CommonBaseBean>() {
            @Override
            public void accept(@NonNull CommonBaseBean bean) throws Exception {
                if("0".equals(bean.getCode())){
                    mView.logoutSuccess();
                }else {
                    mView.logoutSuccess();
                }
            }
        }, new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                ToastUtil.showToast(WEB_FAILED_STR);
            }
        });
    }
}